package com.jhz.speedy.component.receiver;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;

import com.jhz.speedy.common.util.LogUtils;
import com.jhz.speedy.common.util.NetUtils;

/**
 * 网络状态广播监听器
 * Created by JunHeZ on 2017/7/11.
 */
public class NetStateReceiver extends BroadcastReceiver{
    private static final String TAG = NetStateReceiver.class.getSimpleName();

    @Override
    public void onReceive(Context context, Intent intent) {
        if (intent.getAction().equals(ConnectivityManager.CONNECTIVITY_ACTION)) {   // 网络状态发生变化
            boolean isNetworkConnected = NetUtils.isNetworkConnected(context);
            onNetWorkStateChange(isNetworkConnected);
        }
    }

    /**
     * 网络变化
     * @param isNetConnected    是否有网
     */
    private void onNetWorkStateChange(boolean isNetConnected) {
        LogUtils.i(TAG, "onNetWorkStateChange isNetConnected = " + isNetConnected);
        if(isNetConnected){ // 变成有网
        }
    }
}
